import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:fixnum/fixnum.dart' as $fixnum;

import '../../../../../../lib_baseview/widget/empty_view/jr_empty_view.dart';
import '../model/true_love_rank_controller.dart';

/// 真爱榜列表
class TrueLoveRankListPage extends StatefulWidget {
  final $fixnum.Int64? channelId;
  final bool inRoom;

  TrueLoveRankListPage({super.key, this.channelId, this.inRoom = false}) {
    $fixnum.Int64 safeId = TrueLoveRankController.safeChannelId(channelId);
    Get.put(TrueLoveRankController(channelId: safeId), tag: safeId.toString());
  }

  @override
  State<StatefulWidget> createState() => _State();
}

class _State extends State<TrueLoveRankListPage> {
  @override
  Widget build(BuildContext context) {
    return GetBuilder<TrueLoveRankController>(
        tag: TrueLoveRankController.safeChannelId(widget.channelId).toString(),
        builder: (logic) {
          if (logic.errorMsg != null) {
            return JREmptyView(
              errorType: ErrorType.noData,
              desc: logic.errorMsg,
              // onTap: () => logic.loadData(state: LoadState.init),
            );
          }

          // if (logic.data == null) {
          //   return const Center(child: CupertinoActivityIndicator());
          // }

          // if (logic.data!.isEmpty) {
          //   return JREmptyView(
          //       errorType: ErrorType.noData,
          //       desc: T.current!.no_data_click_refresh,
          //       onTap: () => logic.loadData(state: LoadState.init));
          // }

          return RefreshIndicator(
            onRefresh: () async {
              // await logic.loadData(state: LoadState.refresh);
            },
            child: const Text('ListView.builder'),
            // child: ListView.builder(
            //   shrinkWrap: true,
            //   physics: const AlwaysScrollableScrollPhysics(
            //       parent: BouncingScrollPhysics()),
            //   itemBuilder: (c, index) => TrueLoveItemWidget(
            //     item: logic.data![index],
            //     inRoom: widget.inRoom,
            //   ),
            //   itemCount: logic.data!.length,
            //   itemExtent: 80.h,
            //   padding: EdgeInsets.zero,
            // ),
          );
        });
  }

  @override
  void dispose() {
    Get.delete<TrueLoveRankController>(
        tag: TrueLoveRankController.safeChannelId(widget.channelId).toString(),
        force: true);
    super.dispose();
  }
}
